/**
 * Created by zlp on 2018/01/04.
 * For 我的账户
 */
var Promise = require("bluebird");
var request = require("superagent");
var API = require("../support/const");
var setting = require("../../common/cn/member/index");

let templateResult = {
    datas: {},
    setting: setting
};

//登录
exports.login = {
    //登录
    signup_mobile: function (req, res, next) {
        let {mobile, password} = req.body;
        let params = {
            mobile: mobile,
            password: password
        };
        console.log(API.web.login.signup_mobile)
        console.log(params)
        request.put(`${API.web.login.signup_mobile}`)
            .query({msg: JSON.stringify(params)})
            .end(function (_req, _res) {
                res.json(JSON.parse(_res.text));
            });
    },
    //登出
    logout: function (req, res, next) {
        let header = {
            token: req.cookies.token
        };
        request.put(`${API.web.login.logout}`)
            .set(header)
            .end(function (_req, _res) {
                res.json(JSON.parse(_res.text));
            });
    }
};
//注册
exports.reg = {
    //手机注册
    mobile: function (req, res, next) {
        let {mobile, verify_code, password, invite_code} = req.body;
        let params = {
            mobile: mobile,
            verify_code: verify_code,
            password: password,
            invite_code: invite_code
        };
        console.log(API.web.reg.mobile);
        console.log(params);
        request.post(`${API.web.reg.mobile}`)
            .query({msg: JSON.stringify(params)})
            .end(function (_req, _res) {
                res.json(JSON.parse(_res.text));
            });
    },
    //校验手机验证码
    check_verify_code: function (req, res, next) {
        let {mobile, verify_code, password, invite_code} = req.body;
        let params = {
            mobile: mobile,
            verify_code: verify_code,
            password: password,
            invite_code: invite_code
        };
        console.log(params)
        request.put(`${API.web.reg.mobile}`)
            .query({msg: JSON.stringify(params)})
            .end(function (_req, _res) {
                res.json(JSON.parse(_res.text));
            });
    },
    //实名认证
    authentication: function (req, res, next) {
        let {name, mobile, identity_type, identity_no, card_no, verify_code} = req.body;
        let header = {
            token: req.cookies.token
        };
        let params = {
            name: name,
            mobile: mobile,
            identity_type: identity_type,
            identity_no: identity_no,
            card_no: card_no,
            verify_code: verify_code
        };
        console.log(API.web.reg.authentication)
        console.log(header)
        console.log(params)
        request.post(`${API.web.reg.authentication}`)
            .query({msg: JSON.stringify(params)})
            .set(header)
            .end(function (_req, _res) {
                res.json(JSON.parse(_res.text));
            });
    }
};
//密码管理
exports.password = {
    //找回登录密码
    login_retrieve: function (req, res, next) {
        let {mobile, verify_code} = req.body;
        let params = {
            mobile: mobile,
            verify_code: verify_code
        };
        request.get(`${API.web.password.login_retrieve}`)
            .query({msg: JSON.stringify(params)})
            .end(function (_req, _res) {
                //rest_code
                res.json(JSON.parse(_res.text));
            });
    },
    //找回登录密码-重置
    login_retrieve_reset: function (req, res, next) {
        let {reset_code, password} = req.body;
        let header = {
            token: req.cookies.token
        };
        let params = {
            reset_code: reset_code,
            password: password
        };
        request.put(`${API.web.password.login_retrieve_reset}`)
            .query({msg: JSON.stringify(params)})
            .set(header)
            .end(function (_req, _res) {
                res.json(JSON.parse(_res.text));
            });
    },
    //重置登录密码
    login_reset: function (req, res, next) {
        let {password_old, password_new} = req.body;
        let header = {
            token: req.cookies.token
        };
        let params = {
            password_old: password_old,
            password_new: password_new
        };
        request.put(`${API.web.password.login_reset}`)
            .query({msg: JSON.stringify(params)})
            .set(header)
            .end(function (_req, _res) {
                res.json(JSON.parse(_res.text));
            });
    },
    //设置交易密码
    trade_set: function (req, res, next) {
        let {password} = req.body;
        let header = {
            token: req.cookies.token
        };
        let params = {
            password: password
        };
        request.post(`${API.web.password.trade_set}`)
            .query({msg: JSON.stringify(params)})
            .set(header)
            .end(function (_req, _res) {
                res.json(JSON.parse(_res.text));
            });
    },
    //找回交易密码
    trade_retrieve: function (req, res, next) {
        let {mobile, verify_code} = req.body;
        let header = {
            token: req.cookies.token
        };
        let params = {
            mobile: mobile,
            verify_code: verify_code
        };
        request.put(`${API.web.password.trade_retrieve}`)
            .query({msg: JSON.stringify(params)})
            .set(header)
            .end(function (_req, _res) {
                //rest_code
                res.json(JSON.parse(_res.text));
            });
    },
    //找回交易密码-重置
    trade_retrieve_reset: function (req, res, next) {
        let {reset_code, password} = req.body;
        let header = {
            token: req.cookies.token
        };
        let params = {
            reset_code: reset_code,
            password: password
        };
        request.put(`${API.web.password.trade_retrieve_reset}`)
            .query({msg: JSON.stringify(params)})
            .set(header)
            .end(function (_req, _res) {
                res.json(JSON.parse(_res.text));
            });
    },
    //重置交易密码
    trade_reset: function (req, res, next) {
        let {password_old, password_new} = req.body;
        let header = {
            token: req.cookies.token
        };
        let params = {
            password_old: password_old,
            password_new: password_new
        };
        request.put(`${API.web.password.trade_reset}`)
            .query({msg: JSON.stringify(params)})
            .set(header)
            .end(function (_req, _res) {
                res.json(JSON.parse(_res.text));
            });
    }
};